ln: add WASI support via symlink_path#11713
ln: add WASI support via symlink_path#11713DePasqualeOrg wants to merge 6 commits intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
|
|
I added a new commit to address the CI failures. The WASI CI uses stable Rust, but |
|
GNU testsuite comparison: |
fdc57ce to
ea6e1d0
Compare
|
GNU testsuite comparison: |
src/uu/ln/src/ln.rs
Outdated
| pub fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> io::Result<()> { | ||
| use std::os::wasi::ffi::OsStrExt; | ||
|
|
||
| let src_c = CString::new(src.as_ref().as_os_str().as_bytes()) |
There was a problem hiding this comment.
can we use libc or rustix instead?
i really would like to avoid CString
|
could you please add a test? |
|
still need a test :) |
|
It's now using rustix instead. It looks like the existing integration tests cover symlink creation, but CI has |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@oech3 please don't use this PR for this discussion |
|
GNU testsuite comparison: |
|
I have enabled integration tests for WASI in #11717. I suggest that that PR be reviewed first, and after it's merged I can enable symlink tests in this PR. |
On wasm32-wasip1, std::os::unix::fs::symlink is not available, but WASI preview 1 provides path_symlink which Rust exposes as std::os::wasi::fs::symlink_path. Import it under the symlink alias so the existing call site works without changes. Follows the same pattern as cp.rs for enabling wasi_ext.
Avoids Path::exists() returning false for a live symlink whose target stat fails (observed under wasmtime), and also keeps a dangling .~N~ symlink from being overwritten by a --backup=numbered rename.
- test_symlink_to_dir_2args uses an absolute host tmpdir path that isn't visible inside the WASI sandbox. - test_ln_non_utf8_paths requires non-UTF-8 filenames, which WASI forbids. - test_relative_src_already_symlink hits a read_link-on-absolute-path failure specific to wasmtime launched through cargo test's spawn.
Adds test_ln:: to the wasmtime integration test list and drops ln from the pending-tools TODO. Documents the read_link-on-absolute-paths gap in wasi-test-gaps.md.
8b311dd to
0bdca75
Compare
|
Now that #11717 is merged, I've added
One previously failing test ( TestingRan on macOS locally with |
|
GNU testsuite comparison: |
This PR replaces the error-returning WASI stub with a real symlink implementation using
std::os::wasi::fs::symlink_path.Changes
std::os::wasi::fs::symlink_path as symlinkalongside the existing unix and windows symlink importsfn symlinkstub that returnedio::ErrorKind::Unsupported#![cfg_attr(target_os = "wasi", feature(wasi_ext))]for access tostd::os::wasi::fsLimitations
Relative symlink targets work. Absolute symlink targets (e.g.,
ln -s /tmp/foo link) are rejected by WASI runtimes due to capability-based sandboxing — this is a platform constraint, not a code limitation.Build requirements
Rust nightly (for
std::os::wasi::fs, gated withfeature(wasi_ext)).Testing
Verified working on Wasmer and Wasmtime with relative symlink targets.